package com.blb.ioc.demo.util;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Spring工具类
 */
@ComponentScan(basePackages = "com.blb.ioc.demo")
@Configuration
public class SpringUtils {

    //创建上下文
    private static AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringUtils.class);

    /**
     * 返回对象
     */
    public static <T> T getBean(Class<T> clazz){
        return context.getBean(clazz);
    }
}
